home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / pdcurs21.zip / NONPORT.ZIP / WBOX.C < prev    next >
Text File  |  1992-11-20  |  7KB  |  215 lines

  1. #define        CURSES_LIBRARY  1
  2. #include <curses.h>
  3. #undef wbox
  4.  
  5. #ifndef        NDEBUG
  6. char *rcsid_wbox = "$Header: c:/curses/nonport/RCS/wbox.c%v 2.0 1992/11/15 03:18:30 MH Rel $";
  7. #endif
  8.  
  9. /*man-start*********************************************************************
  10.  
  11.   wbox()       - draw box
  12.  
  13.   PDCurses Description:
  14.        Draws a box in window 'win', enclosing the area xmin-xmax and
  15.        ymin-xmax. If xmax and/or ymax is 0, the window max value is
  16.        used. 'v' and 'h' are the vertical and horizontal characters
  17.        to use.  If 'v' and 'h' are PC grapics lines, wbox will make
  18.        the corners in a pretty way.
  19.  
  20.            Single Bar Box                  Double Bar Box
  21.        ----------------------          ======================
  22.        (0xDA)  (0xC4)  (0xBF)          (0xC9)  (0xCD)  (0xBB)
  23.          +       -       +               +       =       +
  24.          | (0xB3)        |               || (0xBA)      ||
  25.          +       -       +               +       =       +
  26.        (0xC0)          (0xD9)          (0xC8)          (0xBC)
  27.  
  28.        PC Graphic Graphic Character Solids:
  29.                # (quarter-tone)        (0xB0)
  30.                # (half-tone)           (0xB1)
  31.                # (three-quarter-tone)  (0xB2)
  32.                # (solid)               (0xDB)
  33.  
  34.   PDCurses Return Value:
  35.        The wbox() function returns OK on success and ERR on error.
  36.  
  37.   PDCurses Errors:
  38.        No errors are defined for this function.
  39.  
  40.   Portability:
  41.        PDCurses        int wbox( WINDOW* win,  int ymin, int xmin,
  42.                                                int ymax, int xmax,
  43.                                                chtype v,   chtype h );
  44.        BSD Curses
  45.        SYS V Curses
  46.  
  47. **man-end**********************************************************************/
  48.  
  49. int    wbox(WINDOW *win,int ymin,int xmin,int ymax,int xmax,chtype v,chtype h)
  50. {
  51.        chtype  l;              /* border chars */
  52.        chtype  r;
  53.        chtype  t;
  54.        chtype  b;
  55.        chtype  tl;
  56.        chtype  tr;
  57.        chtype  bl;
  58.        chtype  br;
  59.        chtype  vattr;
  60.        chtype  hattr;
  61.        int     i;
  62.  
  63.        if (win == (WINDOW *)NULL)
  64.                return( ERR );
  65.        if (ymax == 0)
  66.                ymax = win->_maxy - 1;
  67.        if (xmax == 0)
  68.                xmax = win->_maxx - 1;
  69.  
  70.        if ((ymin >= win->_maxy) ||
  71.            (ymax > win->_maxy) ||
  72.            (xmin >= win->_maxx) ||
  73.            (xmax > win->_maxx) ||
  74.            (ymin >= ymax) ||
  75.            (xmin >= xmax))
  76.        {
  77.                return (ERR);
  78.        }
  79.  
  80.        l = r   = v & A_CHARTEXT;
  81.        t = b   = h & A_CHARTEXT;
  82.  
  83. /* if the incoming character doesn't have its own attribute
  84.    then        use the current attributes for the window.
  85.    if the incoming character has attributes but        not a colour
  86.    component, or the attributes        to the current attributes
  87.    for the window.
  88.    if the incoming character has a colour component use        the
  89.    attributes solely from the incoming character */
  90.  
  91.        if ((h  & A_ATTRIBUTES) == 0)
  92.           hattr        = win->_attrs;
  93.        else
  94.           if ((h & A_COLOR) == 0)
  95.              hattr = (h & A_ATTRIBUTES) | win->_attrs;
  96.           else
  97.              hattr = (h & A_ATTRIBUTES);
  98.  
  99.        if ((v  & A_ATTRIBUTES) == 0)
  100.           vattr        = win->_attrs;
  101.        else
  102.           if ((v & A_COLOR) == 0)
  103.              vattr = (v | win->_attrs);
  104.           else
  105.              vattr = v;
  106.  
  107.        tl = tr = bl = br = l;          /* default same as vertical          */
  108.  
  109.        if (l == 0xba)                  /* vertical double bars              */
  110.        {
  111.                if (t == 0xcd)          /* horizontal too?                   */
  112.                {
  113.                        tl = 0xc9;      /* use double bar corners            */
  114.                        tr = 0xbb;
  115.                        bl = 0xc8;
  116.                        br = 0xbc;
  117.                }
  118.                else
  119.                {
  120.                        tl = 0xd6;         /* use horz-s vert-d corners      */
  121.                        tr = 0xb7;
  122.                        bl = 0xd3;
  123.                        br = 0xbd;
  124.                }
  125.        }
  126.  
  127.        if (l == 0xb3)                     /* vertical single bars           */
  128.        {
  129.                if (t == 0xcd)
  130.                {
  131.                        tl = 0xd5;         /* horizontal double bars         */
  132.                        tr = 0xb8;
  133.                        bl = 0xd4;
  134.                        br = 0xbe;
  135.                }
  136.                else
  137.                {
  138.                        tl = 0xda;         /* use horz-s vert-s bars         */
  139.                        tr = 0xbf;
  140.                        bl = 0xc0;
  141.                        br = 0xd9;
  142.                }
  143.        }
  144.  
  145.        /*
  146.         * wborder() settings override parms
  147.         */
  148.        if (win->_borderchars[0]) l  = win->_borderchars[0];
  149.        if (win->_borderchars[1]) r  = win->_borderchars[1];
  150.        if (win->_borderchars[2]) t  = win->_borderchars[2];
  151.        if (win->_borderchars[3]) b  = win->_borderchars[3];
  152.        if (win->_borderchars[4]) tl = win->_borderchars[4];
  153.        if (win->_borderchars[5]) tr = win->_borderchars[5];
  154.        if (win->_borderchars[6]) bl = win->_borderchars[6];
  155.        if (win->_borderchars[7]) br = win->_borderchars[7];
  156.  
  157.        if  (!(v|h) && !(l|r|t|b|tl|tr|bl|br))
  158.        {
  159.                /*
  160.                 *      Appropriate default:
  161.                 *
  162.                 *      Single box with parent window's title attribute
  163.                 */
  164.                l  = r = 0xb3 | win->_title_attr;
  165.                t  = b = 0xc4 | win->_title_attr;
  166.                tl = 0xda | win->_attrs;
  167.                tr = 0xbf | win->_attrs;
  168.                bl = 0xc0 | win->_attrs;
  169.                br = 0xd9 | win->_attrs;
  170.        }
  171.  
  172.        for (i = xmin + 1; i <= xmax - 1; i++)
  173.        {
  174.                win->_y[ymin][i] = (t | hattr);
  175.                win->_y[ymax][i] = (b | hattr);
  176.        }
  177.  
  178.        for (i = ymin + 1; i <= ymax - 1; i++)
  179.        {
  180.                win->_y[i][xmin] = (l | vattr);
  181.                win->_y[i][xmax] = (r | vattr);
  182.        }
  183.  
  184.        win->_y[ymin][xmin] = (tl | vattr);
  185.        win->_y[ymin][xmax] = (tr | vattr);
  186.        win->_y[ymax][xmin] = (bl | vattr);
  187.        win->_y[ymax][xmax] = (br | vattr);
  188.  
  189.        for (i = ymin; i <= ymax; i++)
  190.        {
  191.                if (win->_firstch[i] == _NO_CHANGE)
  192.                {
  193.                        win->_firstch[i] = xmin;
  194.                        win->_lastch[i] = xmax;
  195.                }
  196.                else
  197.                {
  198.                        win->_firstch[i] = min(win->_firstch[i], xmin);
  199.                        win->_lastch[i] = max(win->_lastch[i], xmax);
  200.                }
  201.        }
  202.        /*
  203.         * set wborder() settings to current values
  204.         */
  205.        win->_borderchars[0] = l  | vattr;
  206.        win->_borderchars[1] = r  | vattr;
  207.        win->_borderchars[2] = t  | hattr;
  208.        win->_borderchars[3] = b  | hattr;
  209.        win->_borderchars[4] = tl | vattr;
  210.        win->_borderchars[5] = tr | vattr;
  211.        win->_borderchars[6] = bl | vattr;
  212.        win->_borderchars[7] = br | vattr;
  213.        return (OK);
  214. }
  215.